﻿
var count = 0;
function cancel(element, str) {
    $("#user_table li").eq(element).find("table").remove();
    $("#user_table li").eq(element).find("input[type=text]").attr("readonly", "true").css("border", "0");
    $("#user_table li").eq(element).find("input[type=text]").val(str);
    count = 0;
    return false;
}
function changeInfo(element, attr) {
    var value = $("#user_table li").eq(element).find("input[type=text]").val();
    $("#user_table li").eq(element).find("input[type=text]").attr("readonly", false);
    $.ajax({
        type: "POST",
        url: "ajax/UpdateElement.ashx?para=" + attr + "&value=" + value + "&key=" + $("#ContentPlaceHolder1_hndusername").val(),
        success: function (data) {
            if (data == "1") {
                $("#user_table li").eq(element).find("table").remove();
                $("#user_table li").eq(element).find("input[type=text]").attr("readonly", true).css("border", "0");
                count = 0;
                return false;
            }
        }
    });
}
$(document).ready(function () {
    $("#UpgradeVIP").click(function () {
        $(this).after("<span id='loading' style='margin-left:5px'><img src='../images/loading_fb.gif' alt='loading...' /></span>");
        $.ajax({
            type: "POST",
            url: "../ajax/UpgradeVIP.ashx",
            success: function (responseText) {
                $("#loading").remove();
                if (responseText == 1) {
                    alert("Nâng cấp thành công.");
                    window.open(location.reload(true));
                }
                else if (responseText == -1) {
                    alert('Lỗi.');
                }
            }
        });
        return false;
    });
    $("img.edit").click(function () {
        if (count == 0) {
            var index = $(this).parent().index();
            var attr = $(this).attr("alt");
            var currentValue = $(this).parent().find("input[type=text]").val();
            $(this).parent().find("input[type=text]").attr("readonly", false).css("border", "1px solid #414141");
            var appendStr = "<table><tr><td><span class='optcontcombell' style='text-align:center'><a href='javascript:void(0);' style='color:#fff' onclick=\"javascript:changeInfo('" + index + "','" + attr + "');\">Update</a></span></td>";
            appendStr += "<td><span class='optcontcombell' style='text-align:center'><a href='javascript:void(0);' style='color:#fff' onclick=\"javascript:cancel('" + index + "','" + currentValue + "');\">Cancel</a></span></td></tr></table>";
            $(this).parent().append(appendStr);
            count++;
        }
    });
});